﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.BPM.Library;
using ZX.EHR.Web;

namespace ZX.WebApp.DeskTop.DeskTopItem
{
    public partial class DealAffair : BasePage
    {
        private string pageType = string.Empty;
        /// <summary>
        /// 待办任务件数
        /// </summary>
        protected int unDoneNum { get; set; }
        /// <summary>
        /// 蔡龙丰为首页未读信息所加
        /// 未读信息数量
        /// </summary>
        protected int unNewsNum { get; set; }
        /// <summary>
        /// 待确认考勤记录数
        /// </summary>
        protected int workResultNum { get; set; }

        /// <summary>
        /// 部门剩余调休
        /// </summary>
        protected decimal remTiaoxiuTimeByDept { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            bindData();
        }

        private int PostType
        {
            get
            {
                int postType = 0;
                if (Request["PostType"] != null)
                    postType = 1;
                return postType;
            }
        }

        /// <summary>
        /// 蔡龙丰为首页未读信息所加
        /// 获取未读信息数量
        /// </summary>
        /// <returns></returns>
        private int GetNoReadNewsCount()
        {
            #region 访问数据库代码
            //打开数据库
            string connString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ToString();
            try
            {
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
                {
                    conn.Open();
                    string sql = "select count(*) from DatSysNewsInfo where readdate is null  and IsDelete=0 and recevePeopleID=@recevePeopleID";
                    System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(sql, conn);
                    com.Parameters.Add("recevePeopleID", System.Data.SqlDbType.UniqueIdentifier);
                    com.Parameters["recevePeopleID"].Value = (Session["User"] as ZX.EHR.Library.DatUser).UserID;

                    int i = Convert.ToInt32(com.ExecuteScalar());
                    return i;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("错误如下：" + e.ToString());
                return 0;
            }
            #endregion
        }

        /// <summary>
        /// 加载时获取待办事宜件数
        /// </summary>
        private void bindData()
        {
            BCrmPayFlow bCrmPayFlow = new BCrmPayFlow();
            //unDoneNum = bCrmPayFlow.GetCountUnDone(this.User.LoginName);
            BHF_TaskInstanceView tv = new BHF_TaskInstanceView();
            unDoneNum = tv.GetTaskInstanceCount("", "", this.User.LoginName, 0, 1);
            unNewsNum = GetNoReadNewsCount();
            //workResultNum = tv.GetWorkResult(this.User.EmpID.ToString());
            workTimeAjax wk = new workTimeAjax();
            workResultNum = wk.GetWorkResult(this.User.EmpID.ToString());
            remTiaoxiuTimeByDept = wk.GetRemTiaoxiuTimeByDept();
            string htmlTemp = "<div style='width:100%;height:100%;font-size: 12px;'>";
            htmlTemp += "   <table cellpadding='0' cellspacing='0' style='width:100%;' border='0'>";
            if (PostType == 0)
            {
                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href='javascript:parent.parent.addTabs(\"待办任务\", \"../Extend/YUIList.aspx?entity=V_HF_TaskInstanceView&functionID=17eae1ad-6f95-44bb-a231-3bfb8276ae81&order=taskStartTime desc\");'>您有【<font color='red'>" + unDoneNum.ToString() + "</font>】件待办的任务</a>";
                htmlTemp += "</tr></td>";

                //蔡龙丰为首页未读信息所加
                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href='javascript:parent.parent.addTabs(\"未读信息\", \"../Extend/YUIList.aspx?entity=V_DatSysNewsInfoNO&functionID=217c66d2-15cf-42c4-b246-925bdb681d27\");'>您有【<font color='red'>" + unNewsNum.ToString() + "</font>】条未读消息</a>";
                htmlTemp += "</tr></td>";

                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href=\"#\" onclick=\"javascript:fnOpenDetail();\">您有【<font color='red'>" + workResultNum.ToString() + "</font>】条待确认的异常考勤记录</a>";
                htmlTemp += "</tr><td>";

                if (remTiaoxiuTimeByDept > 0)
                {
                    htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                    htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                    htmlTemp += "   <a href=\"#\" onclick=\"javascript:fnOpenDeptDetail();\">您部门员工剩余未调休时间共计【<font color='red'>" + remTiaoxiuTimeByDept.ToString() + "</font>】小时，请及时督促员工调休!</a>";
                    htmlTemp += "</tr><td>";
                }
            }
            else
            {
                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href='javascript:window.location=\"../../Extend/YUIList.aspx?entity=V_HF_TaskInstanceView&functionID=17eae1ad-6f95-44bb-a231-3bfb8276ae81&order=taskStartTime desc\"'>您有【<font color='red'>" + unDoneNum.ToString() + "</font>】件待办的任务</a>";
                htmlTemp += "</tr></td>";


                //蔡龙丰为首页未读信息所加
                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href='javascript:parent.parent.addTabs(\"未读信息\", \"../Extend/YUIList.aspx?entity=V_DatSysNewsInfoNO&functionID=217c66d2-15cf-42c4-b246-925bdb681d27\");'>您有【<font color='red'>" + unNewsNum.ToString() + "</font>】条未读消息</a>";
                htmlTemp += "</tr></td>";


                htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                htmlTemp += "   <a href=\"#\" onclick=\"javascript:fnOpenDetailLocation();\">您有【<font color='red'>" + workResultNum.ToString() + "</font>】条待确认的异常考勤记录</a>";
                htmlTemp += "</tr><td>";

                if (remTiaoxiuTimeByDept > 0)
                {
                    htmlTemp += "<tr style='height:30px;'><td style='border-bottom:1px dashed #ccc;'>";
                    htmlTemp += "   <img align='absMiddle' src='../../Images/arrow11.gif' width='9' height='9'>";
                    htmlTemp += "   <a href=\"#\" onclick=\"javascript:fnOpenDeptDetailLocation();\">您部门员工剩余未调休时间共计【<font color='red'>" + remTiaoxiuTimeByDept.ToString() + "</font>】小时，请及时督促员工调休!</a>";
                    htmlTemp += "</tr><td>";
                }
            }
            htmlTemp += "</table></div>";
            Response.Clear();
            Response.Write(htmlTemp);
            Response.End();
        }
    }
}